﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GSLMS.Entity;
using GSLMS.Entity.Enum;
using GSLMS.Core;

namespace GSLMS.WebAPP.Areas.System.Controllers.Dist
{
    public class SurveyTmpSetController : AdminBaseController
    {
        protected override string navTabId
        {
            get { return "System_SurveyTmpSet"; }
        }

        public ActionResult search()
        {
            InitSelectList();
            return View(GetList());
        }

        public ActionResult Index()
        {
            InitSelectList();
            return View(GetList());
        }

        public string TMPTYPE()
        {
            string str = string.Empty;

            str += "<select class='combox' name='DetailList[#index#].TMPTYPE' style='width:220px;'>";
                str+="<option value='0'>--请选择--</option>";
                str+="<option value='1'>客户情况综合认定</option>";
                str+="<option value='2'>项目情况综合认定</option>";
            str+="</select>";

            return str;
        }

        [HttpPost]
        public ActionResult Index(FormCollection collection)
        {
            InitSelectList();

            return View(GetList());
        }

       protected List<GSLMS.Entity.TB_SYS_SURVEYTMPSET> GetList()
        {
            var searchParma = new TB_SYS_SURVEYTMPSET();

            if (ViewData["SearchParma"] != null)
            {
                searchParma = ViewData["SearchParma"] as TB_SYS_SURVEYTMPSET;
               
            }

            return serviceSysSurveyTmpSet.GetList(searchParma);
        }

       

        public ActionResult Create(long id)
        {

            GSLMS.Entity.TB_SYS_SURVEYTMPSET model = new GSLMS.Entity.TB_SYS_SURVEYTMPSET();
            
           
            InitSelectList();

            model = serviceSysSurveyTmpSet.GetByID(id);
            if (model == null)
            {
                model = new TB_SYS_SURVEYTMPSET();

            }
            model.CREATEBY = CurentUser.UserName;
            model.CREATEDATE = DateTime.Now;

            return View(model);
        }

        //
        // POST: /Dictionary/Create

        [HttpPost]
        public string Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                GSLMS.Entity.TB_SYS_SURVEYTMPSET model = new GSLMS.Entity.TB_SYS_SURVEYTMPSET();
                TryUpdateModel(model, collection);
                bool result =false;
                result = model.ID > 0 ? serviceSysSurveyTmpSet.Update(model) : serviceSysSurveyTmpSet.Add(model);
                if (result)
                {

                    ajaxStr = string.Format(ajaxStr, 200,
                        ResourceManager.SaveSuccess,
                        navTabId,
                        "",
                         "closeCurrent");
                }
                else 
                {
                    ajaxStr = string.Format(ajaxStr, 300, ResourceManager.SaveFail, navTabId, "", "");
                }

            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                ajaxStr = string.Format(ajaxStr, 300, ResourceManager.SaveFail, navTabId, "", "");
            }
            return "{" + ajaxStr + "}";
        }

        //
        // GET: /Dictionary/Delete/5
        [HttpPost]
        public string Delete(long id)
        {
            try
            {
                if (serviceSysSurveyTmpSet.Delete(id))
                {
                    ajaxStr = string.Format(ajaxStr, 200, ResourceManager.DeleteSuccess, navTabId, "", "");
                }
                else
                {
                    ajaxStr = string.Format(ajaxStr, 300, ResourceManager.DeleteFail, navTabId, "", "");
                }
            }
            catch (Exception ex)
            {
                ExceptionHand(ex);
                ajaxStr = string.Format(ajaxStr, 300, ResourceManager.DeleteFail, navTabId, "", "");
            }

            InitSelectList();

            return "{" + ajaxStr + "}";
            
        }

        private void InitSelectList()
        {


            var searchParma = new GSLMS.Entity.TB_SYS_SURVEYTMPSET();
           if (ViewData["SearchParma"] != null)
           {
               searchParma = ViewData["SearchParma"] as TB_SYS_SURVEYTMPSET;
           }


           ViewData["SearchParma"] = searchParma ?? new TB_SYS_SURVEYTMPSET();

           ViewData["SystemDataList"] = EnumHelper.ToSelectList<SystemEnum.SystemID>();
           ViewData["surveyTypeDataList"] = EnumHelper.ToSelectList<SystemEnum.SurveyType>();
            //ViewData["UserDataList"] = new SelectList(serviceEmp.GetUserEffList(), "username", "empname");
            

        }


    }
}
